import * as types from './mutation-types'
import {appRouter} from '@/router/router'

export default {
  [types.LOGOUT] (state) { // 退出登录
    localStorage.clear()
  },
  [types.SETMENULIST] (state) {
    let menuList = []
    appRouter.forEach((item, index) => {
      if (item.children.length === 1) {
        menuList.push(item)
      } else {
        let len = menuList.push(item)
        let childrenArr = []
        childrenArr = item.children
        let handledItem = JSON.parse(JSON.stringify(menuList[len - 1]))
        handledItem.children = childrenArr
        menuList.splice(len - 1, 1, handledItem)
      }
    })
    state.menuList = menuList
  },
  [types.SETSEDMENULIST] (state, list) {
    state.sedMenuList = list
  },
  [types.SETH] (state, h) {
    state.h = h
  },
  [types.SETCOLOR] (state, color) {
    state.color = color
  }
}
